//
//  YKHttpTool.m
//  youkan
//
//  Created by mac mini on 16/2/29.
//  Copyright © 2016年 Honsintech. All rights reserved.
//

#import "YKHttpTool.h"
#import "AFNetworking.h"
@implementation YKHttpTool
+(void)GET:(NSString *)URLString parameters:(id)parameters success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    AFHTTPSessionManager *manager =[AFHTTPSessionManager manager];
    [manager GET:URLString parameters:parameters progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (success) {
            success(responseObject);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
        }
    }];

}

+(void)POST:(NSString *)URLString parameters:(id)parameters success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    AFHTTPSessionManager *manger = [AFHTTPSessionManager manager];
    [manger POST:URLString parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (success) {
            success(responseObject);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
        }
    }];
//    AFHTTPRequestOperationManager *manager =[AFHTTPRequestOperationManager manager];
//    manager.responseSerializer = [AFJSONResponseSerializer serializer];
//    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/plain", nil];
//[manager POST:URLString parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
//    if (success) {
//        success(responseObject);
//    }
//} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//    if (failure) {
//        failure(error);    }
//}];
}
+(void)Upload:(NSString *)URLString parameters:(id)parameters uploadParam:(YKUplodParam *)Upparam success:(void (^)(id))success failure:(void (^)(NSError *))failure{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:URLString parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
         [formData appendPartWithFileData:Upparam.data name:Upparam.name fileName:Upparam.fileName mimeType:Upparam.mimeType];
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (success) {
            success(responseObject);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
        }
    }];
//    AFHTTPRequestOperationManager *manager =[AFHTTPRequestOperationManager manager];
//
//    [manager POST:URLString parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
//        /**
//         *  FileData:要上传的文件的二进制数据
//         *  name:上传参数名称
//         *  fileName：上传到服务器的文件名称
//         *  mimeType：文件类型
//         */
//        [formData appendPartWithFileData:Upparam.data name:Upparam.name fileName:Upparam.fileName mimeType:Upparam.mimeType];
//    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        if (success) {
//            success(responseObject);
//        }
//    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//        if (failure) {
//            failure(error);
//        }
//    }];
}
@end
